package com.gz.logistics.library.listener;

import com.gz.logistics.library.pojo.OrderDetail;
import com.gz.logistics.library.pojo.OrderInfo;
import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * 获取订单详情监听
 * author wanner1991
 */
public abstract class GetQueryorderDetailListener extends BaseListener {
    private String TAG = GetQueryorderDetailListener.class.getSimpleName();

    public GetQueryorderDetailListener(RequestCode requestCode) {
        super(requestCode);
    }

    protected GetQueryorderDetailListener() {
    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_STATUS);
            String msg = response.getString(Constants.REQ_MSG);
            CrashHandler.i(TAG, response.toString());
            switch (status) {
                case Constants.REQ_OK:
                    JSONObject jsonobject = response.getJSONObject(Constants.REQ_RESULT);
                    onResponseSuccess(OrderDetail.parse(jsonobject));
                    break;
            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }


    @Override
    public void onOffline() {

    }

    @Override
    public void onNoMoreData() {

    }

    @Override
    public void onFailure(int statusCode, Header[] headers,
                          Throwable throwable, JSONObject errorResponse) {
        CrashHandler.e(throwable);
        onResponseFailed();
    }

    public abstract void onResponseSuccess(OrderDetail orderDetails);
}